import { ReactNode } from 'react';
import { usePermission } from '~/hooks/usePermission';

interface PermissionGuardProps {
  permission: string | string[];
  mode?: 'every' | 'some';
  fallback?: ReactNode;
  children: ReactNode;
}

export function PermissionGuard({
  permission,
  mode = 'every',
  fallback = null,
  children
}: PermissionGuardProps) {
  const { checkPermissions } = usePermission();
  const permissions = Array.isArray(permission) ? permission : [permission];
  
  if (!checkPermissions(permissions, mode)) {
    return <>{fallback}</>;
  }

  return <>{children}</>;
}